<template>
    <div>
        <h2>房号录入</h2>
        <table class="table table-bordered">
<tr>
    <td align="right">房型id</td>
    <td><input type="text" v-model="state.mid" /></td>
</tr>
<tr>
    <td align="right">房号</td>
    <td><input type="text" v-model="state.hId" /></td>
</tr>

<tr>
    <td align="right">排序</td>
    <td><input type="text" v-model="state.orderby" /></td>
</tr>
<tr>
    <td align="right">门店id</td>
    <td><input type="text" v-model="state.did" /></td>
</tr>
<tr>
    <td align="right"></td>
    <td><input type="button" value="录入" @click="add" /></td>
</tr>
</table>
    </div>
</template>

<script setup lang="ts">
import { reactive,toRefs } from 'vue';
import { useRouter,useRoute } from 'vue-router';
import axios from 'axios';
const router=useRouter();
let data=reactive({
    state:{
        mid:'',
        hId:'',
        orderby:'',
        did:'',
    }
})

let{state}=toRefs(data)

const add=()=>{

if(state.value.mid==""){
    alert("房型id不能为空")
    return;
}
if(state.value.hId==""){
    alert("房号不能为空")
    return;
}
    let obj={
        id: 0,

  mid:  state.value.mid,
  hId:  state.value.hId,
  orderby:  state.value.orderby,
  did:  state.value.did,
  state: 0,
  isDeleted: false
    }
    axios({
        url:'/api/HouseNum/HouseNumAdd',
        method:'post',
        data:obj
    })
    .then(res=>{
        console.log(res)
        if(res.data==1){
            alert("录入成功")
            router.push("/HNlist")
        }
        else{
            alert("录入失败")
            return;
        }
    })
    .catch(err=>{
        console.log(err)
    })
}
</script>

<style scoped>

</style>